package com.lecture.java8.excel.dyr.f;

import com.alibaba.excel.EasyExcel;
import com.lecture.java8.excel.DemoDataListener;
import com.lecture.java8.excel.dyr.model.Model;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Test0712 {
    public static void main(String[] args) {
        String dir = "D:\\study\\tmp\\0712\\";


        String resultPath = dir + "上市企业新质生产力-计算结果.xlsx";
        DemoDataListener<Result0712> dataResultListener = new DemoDataListener<>();
        EasyExcel.read(resultPath, Result0712.class,dataResultListener).sheet().doRead();
        //全要素生产率
        List<Result0712> resultList = dataResultListener.getDataList();
        Map<String,Result0712> resultMap = new HashMap<>();
        for (Result0712 result : resultList) {
            resultMap.put(result.getA() + "-" + result.getB(),result);
        }

        String result1 = dir + "正在使用的.xlsx";
        DemoDataListener<Model> modelListener = new DemoDataListener<>();
        EasyExcel.read(result1, Model.class,modelListener).sheet().doRead();
        //全要素生产率
        List<Model> modelList = modelListener.getDataList();
        for (Model model : modelList) {
            Result0712 result = resultMap.get(model.getA() + "-" + model.getB());
            if (result != null) {
                model.setAr(result.getC());
                model.setAs(result.getD());
            }
        }

        EasyExcel.write( dir + "0712结果.xlsx", Model.class)
                .sheet("a").doWrite(modelList);

    }
}
